#include <algorithm>
#include <cctype>
#include <string>
#include <vector>
#include <iterator>
#include <iostream>
template <class In, class Out, class Pred >
Out copy_if (In first, In last ,Out res, Pred p )
{
    while (first != last ) {
        if (p (*first )) *res ++ = *first ;
        ++first ;
    }
    return res ;
}
struct LowerCase
{
    std::string operator()(const std::string& str){
        int length = str.length();
        std::string ret = str;
        for(int i = 0; i < length; ++i){
            ret[i] = std::tolower(ret[i]);
        }
        return ret;
    }
};
bool start_a(std::string& str)
{
    return str[0] == 'a';
}

void process_data(std::vector<std::string>& fruit){
    sort(fruit.begin(), fruit.end());
    copy(fruit.begin(), fruit.end(),
         std::ostream_iterator<std::string> (std::cout, " "));
    std::cout << "Copy only a" << std::endl;
    copy_if(fruit.begin(), fruit.end(),
            std::ostream_iterator<std::string> (std::cout, " "),
            start_a);
}

int main()
{
    std::string fruit;
    std::vector<std::string> fruits;
    while((std::cin >> fruit) and (fruit[0] != '.')){
        fruits.push_back(fruit);
    }
    std::transform(fruits.begin(), fruits.end(),
                   fruits.begin(), LowerCase());    
    process_data(fruits);
    return 0;
}



            
        
            
